home *** CD-ROM | disk | FTP | other *** search
- VERSION 2.00
- Begin Form Form1
- AutoRedraw = -1 'True
- BorderStyle = 1 'Fixed Single
- Caption = "AutoRedraw Demo"
- ClientHeight = 2880
- ClientLeft = 1185
- ClientTop = 1800
- ClientWidth = 3960
- ClipControls = 0 'False
- Height = 3285
- Left = 1125
- LinkTopic = "Form1"
- MaxButton = 0 'False
- ScaleHeight = 192
- ScaleMode = 3 'Pixel
- ScaleWidth = 264
- Top = 1455
- Width = 4080
- Option Explicit
- Const PIXEL = 3
- Dim PI As Double
- Dim DegreesPerRadian As Double
- Dim RadiansPerDegree As Double
- 'This next constant should generally be a power of 2.
- Const SECTORCOUNT = 8
- Sub Form_Activate ()
- Const DELTA = 400
- Const RADIUS = 1
- Dim i As Integer
- Dim theta As Double
- Dim x1 As Single, y1 As Single
- form1.Height = form1.Width + DELTA
- form1.ScaleMode = PIXEL
- 'Scale requires the coordinates of the upper left and lower right.
- Scale (-1, 1)-(1, -1)
- 'To make the circle and the lines persistant,
- 'set AutoRedraw to True before drawing them.
- form1.AutoRedraw = True
- 'Draw a unit circle.
- Circle (0, 0), RADIUS
- 'Draw the lines as needed.
- For i = 1 To SECTORCOUNT
- y1 = Sin(theta)
- x1 = Cos(theta)
- Line (x1, y1)-(0, 0)
- theta = theta + PI / (SECTORCOUNT / 2)
- Next i
- form1.AutoRedraw = False
- End Sub
- Sub Form_Load ()
- 'Let the computer determine a value for PI.
- PI = 4# * Atn(1)
- DegreesPerRadian = 180# / PI
- RadiansPerDegree = PI / 180#
- End Sub
- Sub Form_MouseDown (Button As Integer, Shift As Integer, x As Single, y As Single)
- Dim sector As Integer
- Dim radians As Double
- Dim degrees As Double
- Dim hypotenuse As Double
- 'Only allow clicking inside the circle.
- hypotenuse = Sqr(x * x + y * y)
- If hypotenuse > 1# Then
- Exit Sub
- End If
- radians = Atn(y / x)
- degrees = radians * DegreesPerRadian
- If x < 0# Then
- degrees = 180# + degrees '2nd & 3rd quadrant
- ElseIf y < 0# Then
- degrees = 360# + degrees '4th quadrant
- End If
- sector = Int(degrees / (360# / SECTORCOUNT)) + 1
- MsgBox "You clicked in sector #" + Str$(sector) + "."
- End Sub
-